package com.wzy.pipeline;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: wzy
 * @Date: 2021/12/11/14:24
 * @Description:
 */
@Service
public class ModelServiceImpl {
    @Autowired
    private PipelineExecutor pipelineExecutor;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public CommonResponse<Long> buildModelInstance(InstanceBuildRequest request) {
        InstanceBuildContext data = createPipelineData(request);
        boolean success = pipelineExecutor.acceptSync(data);


        // 创建模型实例成功
        if (success) {
            return CommonResponse.success(data.getInstanceId() + "");
        }


        logger.error("创建模式实例失败：{}", data.getErrorMsg());
        return CommonResponse.failed(data.getErrorMsg()+"");
    }

    private InstanceBuildContext createPipelineData(InstanceBuildRequest request) {
        InstanceBuildContext context = new InstanceBuildContext();
        context.setModelId(request.getModelId());
        context.setUserId(request.getUserId());
        context.setFormInput(request.getFormInput());
        context.setInstanceId(request.getInstanceId());

        return context;
    }
}
